#ifdef _DEBUG
//#include <vld.h>
#endif

#include <iostream>
#include <cstdlib>
#include <ctime>
#include "EpilInterpreter.h"
#include "EpilException.h"
#include "EpilNativeFunctionObject.h"

using namespace std;


EpilObjectVector Print( EpilInterpreter * interpreter, const EpilObjectVector & params )
{
	for( EpilObjectVector::const_iterator it = params.begin(); it != params.end(); ++it )
	{
		tcout << (*it)->ToString() << endl;
	}
	return EpilObjectVector();
}


EpilObjectVector Random( EpilInterpreter * interpreter, const EpilObjectVector & params )
{
	int r = rand();
	EpilObjectVector ret;
	ret.push_back( interpreter->CreateNumberObject( r ) );
	return ret;
}


EpilObjectVector TestTwoReturns( EpilInterpreter * interpreter, const EpilObjectVector & params )
{
	EpilObjectVector ret;
	ret.push_back( params[0] );
	ret.push_back( params[1] );
	return ret;
}


int main( int argc, char * argv[] )
{
	srand( static_cast<unsigned int>( time( NULL ) ) );

	EpilInterpreter interpreter;
	interpreter.RegisterFunction( t("Test"), TestTwoReturns );
	interpreter.RegisterFunction( t("rand"), Random );

	try
	{
		interpreter.RunFile( t("Test.epil") );
	}
	catch( const EpilException & e )
	{
		tcout << e.GetCompleteMessage() << endl;
	}

	system( "PAUSE" );
	return 0;
}